<?php

namespace Admin\Controllers;

use Platform\Controller;
use Platform\Models\Organize\Leader;
use Platform\Models\Organize\Organize;
use Platform\System\Tools\ResultTool;

class BaseAdminController extends Controller
{
    protected $phone_preg = "/^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$/";
    protected $cache_area_key;
    protected $admin;
    protected $organize;
    protected $auth_type = 'admin';
    protected $app_type = null;

    public function __construct()
    {
        $token = auth($this->auth_type)->getToken();
        if ($token){
            if (auth($this->auth_type)->user()) {
                $this->admin = auth($this->auth_type)->user() ;
            }
        }
    }

    /**
     * 获取当前的目标组织
     * @param Organize|null $organize
     * @return Organize
     */
    public function getOrganize(Organize $organize = null){

        if ($organize) {
            return $this->organize = $organize;
        }

        $organize_id = request('organize',null);
        if (!$organize_id)
            myResult()->stop(ResultTool::CODE_TARGET_WRONG,'请先选择组织');

        $this->organize = Organize::find($organize_id);
        if (!$this->organize)
            myResult()->stop(ResultTool::CODE_TARGET_WRONG,'目标组织不存在');

    }
}